package dbserver;

import java.util.ArrayList;
import java.util.Hashtable;

public abstract class DataModel implements Observable, Model {
	private DataReader dataProcessor;
	private Record currentRecord;
	private ArrayList<Observer> observers = new ArrayList<Observer>();
	protected Properties properties;
	
	public Record getRecord() {
		return currentRecord;
	}
	
	public DataModel(Properties properties){
		this.properties = properties;
		dataProcessor = createDataProcessor();
	}

	public void setRecord(Record Record) {
		this.currentRecord = Record;
	}

	public Properties getProperties() {
		return properties;
	}
	
	public void setProperties(Properties props){
		this.properties = props;
	}
	
	public abstract DataReader createDataProcessor();

	public void addObserver(Object o) {
		observers.add((Observer)o);
	}

	public void removeObderver(Object o) {
		// TODO Auto-generated method stub
	}

	public void notifyObservers() {
		for(Observer o: observers){
			o.update(this);
		}
	}

	public void findText(String strToFind){
		currentRecord = dataProcessor.findRecord(strToFind);
		if(currentRecord == null){
			currentRecord = new Record(-1, "", "There is no such term in the dictionary");
		}
		notifyObservers();
	}

	public Record getCurrentState() {
		return currentRecord;
	}
}
